package com.mingzhi.lotterysystem.dao.mapper;

import com.mingzhi.lotterysystem.dao.dataobject.PrizeDO;
import jakarta.validation.constraints.NotEmpty;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize(name,image_url,price,description)" +
            " values (#{name},#{imageUrl},#{price},#{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer insert(PrizeDO prizeDO);

    //如果当前有主键，会根据主键查取数量
    @Select("select count(1) from prize")
    Integer count();

    @Select("select * from prize order by id desc limit #{offset},#{pageSize}")
    List<PrizeDO> selectPrizeList(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDO> batchSelectByIds(@Param("items") List<Long> prizeIds);

    /**
     * 根据奖品id查询奖品信息
     *
     * @param id
     * @return
     */
    @Select("select * from prize where id = #{id}")
    PrizeDO selectById(@Param("id") Long id);
}
